﻿namespace Arms.Presentation.Web.Common
{
    using System;
    using System.Web;
    using System.Web.Security;

    public class FormsService : IFormsService
    {
        public HttpCookie CreateUserAuthHttpCookie(string userName, string cookieUserData, bool createPersistentCookie)
        {
            int version = 1;
            var now = DateTime.Now;

            // respect to the 'timeout' in Web.config
            var timeout = FormsAuthentication.Timeout;
            var expire = now.Add(timeout);

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                 version,
                 userName,
                 now,
                 expire,
                 createPersistentCookie,
                 cookieUserData);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
            cookie.Secure = FormsAuthentication.RequireSSL;

            return cookie;
        }

        public void SignOut()
        {
            FormsAuthentication.SignOut();
        }
    }
}
